//209. 长度最小的子数组
//https://leetcode.cn/problems/minimum-size-subarray-sum/description/
// 中等

#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        const int MAX_VALUE = 1e5 + 10;
        size_t result = MAX_VALUE;
        size_t sum=0;
        for(size_t l=0,r=0; r<nums.size(); ){
            sum += nums[r++];
            while(sum >= target){
                result = min(result, r-l);
                sum -= nums[l++];
            }
        }
        return result == MAX_VALUE ? 0:result;
    }
};

